﻿using System;
using System.Collections.Generic;
using System.IO;

namespace AutoExecuteSp
{
    public class AutoScript
    {
        ScriptPicker scriptPicker = new ScriptPicker();
        ScriptProcessor scriptProcessor = new ScriptProcessor();
        ScriptLogger scriptLogger = new ScriptLogger();

        public void Run()
        {
            List<FileInfo> fileInfos = scriptPicker.PickAllFile();

            bool isToExcuteSql = ConfigReader.GetValue<bool>("IsToExcuteSql");

            if (isToExcuteSql)
            {
                List<ExecuteResult> executeResults = new List<ExecuteResult>();

                foreach (FileInfo fileInfo in fileInfos)
                {
                    executeResults.Add(scriptProcessor.ExeCommand(fileInfo));
                }

                scriptLogger.Log(executeResults);
            }

            ConfigReader.SetConfiguration("StartDate", DateTime.Now.ToString());
        }
    }
}
